import {covertTableData} from '@/utils/tableUtil'
import {request} from '@umijs/max'
import {KfMessageVO} from 'types/kf'
import {NFBaseService} from './NFBaseService'
import {PageParam} from "@/services/common";

/*User*/
export interface User {
    id: string
    type: string
    openid: string
    token: string
    nickname: string
    avatar: string
    code: string
    unionId: string
    creator: string
    createTime: string
    updater: string
    updateTime: string
    deleted: boolean
    tenantId: string
    appId: string
}

/*tsModel1*/
export interface Dialogue {
    id: string
    user: User
    userId: string
    scope: number
    appType: string
    appId: string
    creator: string
    createTime: string
    updateTime: string
    deleted: boolean
    tenantId: string
    lastMessage: string
    unreadTotal: number
    top: boolean
}

export interface CommunicateVO {
    id: string
    lastMessage: string
    user: string
    updateTime: string
}

export interface DialogueDTO {
    current: number
    pageSize: number
    dialogueId: string
}

export interface Message {
    /**
     * ��Ϣ����
     */
    content?: string
    /**
     * ����ʱ��
     */
    createTime?: string
    /**
     * ������
     */
    creator?: string
    /**
     * ��ǰҳ
     */
    current?: number
    /**
     * �Ƿ�ɾ��
     */
    deleted?: string
    /**
     * �Ựid
     */
    dialogueId?: string
    /**
     * ���
     */
    id?: string
    /**
     * �Ƿ��Ѷ�
     */
    isRead?: string
    /**
     * ��Ϣ����
     */
    messageType?: string
    /**
     * ҳ���С
     */
    pageSize?: number
    /**
     * �Ѷ�ʱ��
     */
    readTime?: string
    /**
     * �⻧id
     */
    tenantId?: string
    /**
     * ������
     */
    updater?: string
    /**
     * ����ʱ��
     */
    updateTime?: string
}

export const getDialoguePage = async (params: DialogueDTO) => {
    let response = await request<Message[]>(`/api/v2/message/messagePage`, {method: 'GET', params})
    return covertTableData(response)
}


interface KfMessageQueryDTO extends Required<PageParam> {
    dialogueId: string
}

class KfMessageService extends NFBaseService<KfMessageVO, KfMessageQueryDTO, Dialogue> {
    protected _bizName: string = 'message'
    protected _bizApi = '/api/v2'
}

export const kfMessageService = new KfMessageService()
export const getCommunicateVO = async (params?: { current: number; pageSize: number }) => {
    let resp = await request<CommunicateVO>(`/api/v2/dialogue/schema`, {
        method: 'GET',
        params: params,
        pagesize: 1,
        current: 1,
    })
    return resp
}
